﻿using System;
using System.Collections.Generic;
using System.Text;
using Entity;
using System.Data;
using System.Data.SqlClient;
using ECommerce.DAL;

namespace Entity
{
    [System.ComponentModel.DataObject]
    public class TblAddressBookExtended : TblAddressBook
    {

        public static ECommerce.DAL.CustomCollection<TblAddressBook> GetBackendAddressBookListByCondition(string condition, string sortBy, int firstItem, int pageSize)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();

            AddParameterToSqlCmd(sqlCmd, "@Condition", SqlDbType.NVarChar, 2000, ParameterDirection.Input, condition);
            AddParameterToSqlCmd(sqlCmd, "@Orderby", SqlDbType.NVarChar, 500, ParameterDirection.Input, sortBy);
            AddParameterToSqlCmd(sqlCmd, "@CurrentPageIndex", SqlDbType.Int, 0, ParameterDirection.Input, firstItem);
            AddParameterToSqlCmd(sqlCmd, "@PageSize", SqlDbType.Int, 0, ParameterDirection.Input, pageSize);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_ADDRESS_BOOK__GET_LIST_BY_CONDITION);
            GenerateCollectionFromReader reader = new GenerateCollectionFromReader(GenerateTblAddressBookCollectionFromReader);
            CustomCollection<TblAddressBook> objCollection = ((CustomCollection<TblAddressBook>)ExecuteReaderCmd(sqlCmd, reader));

            return objCollection;
        }

        public static int GetBackendAddressBookListByConditionCount(string condition)
        {
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@Condition", SqlDbType.NVarChar, 2000, ParameterDirection.Input, condition);
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_ADDRESS_BOOK_GET_LIST_BY_CONDITION_COUNT);
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }
        private const string SP_TBL_ADDRESS_BOOK__GET_LIST_BY_CONDITION = "sp_TblAddressBook_Get_List_By_Condition";
        private const string SP_TBL_ADDRESS_BOOK_GET_LIST_BY_CONDITION_COUNT = "sp_TblAddressBook_Get_List_By_Condition_Count";
       

    }
}
